<?php

namespace App\Imports\Ekb;

use App\Models\OpenShop\Common\SupplierShopCodeRelModel;
use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\ToCollection;

class SupplierShopCodeRelImport implements ToCollection
{
    /**
     * @param Collection $collection
     */
    public function collection(Collection $collection)
    {
        $collection->shift();

        $collection->each(function (Collection $v, $k) {
//            echo $k."=====".$v->toJson(JSON_UNESCAPED_UNICODE).PHP_EOL;
//            echo "第 {$k} 行" . PHP_EOL;
//            $supplierCode     = $v->get(0);
//            $shopCode =$v->get(2);
//            echo $shopCode."======".mb_substr($v->get(2), 0, 4) . "=+++=" . $supplierCode;
//            die;
            SupplierShopCodeRelModel::query()->insert([
                "supplierCode" => $v->get(0),
                "shopCode"     => mb_substr($v->get(2), 0, 4)
            ]);
        });
    }
}
